package com.zhiyou100.interface_demo2;

/**
 * 电脑类
 */
public class Computer {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    //电脑启动
    public void startUp(){
        System.out.println(name + "电脑启动起来了.......");
    }


    //定义一个方法，电脑使用这个usb接口,将USB作为参数，此时利用多态
    public void useUSB(USB usb){
        //通过类型判断，给我们的设备添加一个名字
        if (usb instanceof Mouse){
            Mouse mouse = (Mouse) usb;
            mouse.setName("罗技M2");
        }
        if (usb instanceof Keyboard){
            Keyboard keyboard = (Keyboard) usb;
            keyboard.setName("双飞燕");
        }
        usb.function();
        usb.connect();
        usb.exit();
    }
}
